package com.lz.spring.cloud.feign.control;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.lz.spring.cloud.feign.client.CalcFeignClient;


@RestController
public class CalcControl {

	protected static Logger LOGGER = LoggerFactory.getLogger(CalcControl.class);
	
	@Autowired
	private CalcFeignClient calcFeignClient;
	
    @Autowired
    private LoadBalancerClient loadBalancer;
    
	@GetMapping("/add/{a}/{b}")
	public String add(@PathVariable Integer a, @PathVariable Integer b){
		ServiceInstance instance = this.loadBalancer.choose("03-spring-eureka-client");
		if(instance != null){
			LOGGER.info("====" + instance.getServiceId() + ":" + instance.getHost() + ":" + instance.getPort());
		}
		return calcFeignClient.add(a, b);
	}
}
